﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Ebada.Modules.Vehicle
{
    /// <summary>
    /// 随行人员登记编辑
    /// </summary>
    public partial class frmVehicleDispatchEmpEdit : FormBase, IPopupFormEdit {

        public frmVehicleDispatchEmpEdit()
        {
            InitializeComponent();
        }
        private void frmVehicleDispatchEmpEdit_Load(object sender, EventArgs e)
        {

           

        }
        void dataBind() 
        {

            this.txtVehicleDispatchID.DataBindings.Add("EditValue", rowData, "VehicleDispatchID");
            this.txtEmployeeNo.DataBindings.Add("EditValue", rowData, "EmployeeNo");
            this.luEmployeeName.DataBindings.Add("EditValue", rowData, "EmployeeNo");
            this.meRemark.DataBindings.Add("EditValue", rowData, "Remark");
           
        }
       
        #region IPopupFormEdit Members
        private VehicleDispatchEmp rowData = null;

        public object RowData {
            get {
                return rowData;
            }
            set {
                if (value == null) return;
                if (rowData == null) {
                    this.rowData = value as VehicleDispatchEmp;
                    dataBind();
                    InitComboBoxData();
                } else {
                    ConvertHelper.CopyTo<VehicleDispatchEmp>(value as VehicleDispatchEmp, rowData);
                   
                }
            }
        }

        #endregion

        private void InitComboBoxData() 
        {
           IList<Empolyees> empl_list = MainHelper.PlatformSqlMap.GetList<Empolyees>("");
           this.SetComboBoxData(this.luEmployeeName, "Empolyee_Name", "Empolyee_ID", "请选择", "人员名称", empl_list);
         
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="displayMember"></param>
        /// <param name="valueMember"></param>
        /// <param name="nullTest"></param>
        /// <param name="cnStr"></param>
        /// <param name="post"></param>
       //人员选择器
        public void SetComboBoxData(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, IList<Empolyees> post)
        {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }


        private void btnOK_Click(object sender, EventArgs e)
        {
          
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
       
        //选择领用人
        private void luEmployeeID_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 1)
            {
                Ebada.Client.Platform.Selector.frmEmpSelectorByOrgInfo frm = new Ebada.Client.Platform.Selector.frmEmpSelectorByOrgInfo();
                frm.InitionData("", false, false);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    luEmployeeName.EditValue = frm.CurrentEmp.Empolyee_ID;
                    txtEmployeeNo.Text = frm.CurrentEmp.Empolyee_ID;
                    rowData.EmployeeName = frm.CurrentEmp.Empolyee_Name;

                }
            }
        }

        private void luEmployeeName_EditValueChanged(object sender, EventArgs e)
        {
            txtEmployeeNo.Text = luEmployeeName.EditValue.ToString();
            rowData.EmployeeName = luEmployeeName.Text;
       

        }
      

      
    }
}